﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;

namespace QuanLyShopThoiTrang_DAO
{
    public class DataProvider
    {
        private static string ConnectionString = @"Data Source=ADMIN-PC\SQLEXPRESS;Initial Catalog=QuanLyShopQuanAo;Integrated Security=True";

        private SqlConnection connection = null;
        public SqlConnection Connection
        {
            get { return connection; }
            set { connection = value; }
        }

        private static DataProvider provider = null;
        public static DataProvider Instance()
        {
            if (provider == null)
            {
                try
                {
                    provider = new DataProvider();
                    provider.Connection = new SqlConnection(ConnectionString);
                }
                catch
                {
                    provider = null;
                }
            }
            return provider;
        }

        public static void OpenConnection()
        {
            provider.Connection.Open();
        }

        public static void CloseConnection()
        {
            provider.Connection.Close();
        }

        public SqlDataReader executeReader(string sql)
        {
            SqlCommand cmd = new SqlCommand(sql, provider.Connection);
            return cmd.ExecuteReader();
        }

        public void executeQuery(string sql)
        {
            SqlCommand cmd = new SqlCommand(sql, provider.Connection);
            cmd.ExecuteNonQuery();
        }
    }
}